﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;

namespace Sniffer
{
   
    public class Class1 
    {
        ForegroundWindowListener listener;
        String testFile = @"C:\Study\Programming\CSHarpWorkspace\Neighborhood\TestFolder\test.txt";

        public String TestFile
        {
            get { return testFile; }
            set { testFile = value; }
        }
        public ForegroundWindowListener Listener
        {
            get { return listener; }
        }
        public void Init()
        {
            listener = new ForegroundWindowListener();
            listener.OnForegroundChange += listener_OnForegroundChange;
        }

        private void listener_OnForegroundChange(object sender, ForegroundChangeEventArgs e)
        {

            using (System.IO.StreamWriter file = new System.IO.StreamWriter(testFile, true))
            {
                file.WriteLine(e.WindowName);
            }
            //Console.WriteLine(e.WindowName);
            //for browser sniffing redirect to webSniffer
            //for app sniffer redirect to appSniffer
        }
        //delete this later
        public void SniffLog(String log) {
            listener_OnForegroundChange(null, new ForegroundChangeEventArgs(log));
        }
    }
}
